<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text" id="ipt">
    <script>
        let obj =  {};
        var val =  '';

        Object.defineProperty(obj,'msg',{
            set(newVal){
                console.log('设置值')
                val = newVal;
                document.querySelector('#ipt').value = newVal
            },
            get(){
                console.log('获取值')
                return val 
            }
        })

        document.querySelector('#ipt').addEventListener('input',(e)=>{
            obj.msg = e.target.value
        })
    </script>
</body>
</html>